package fr.afcepf.ai89.esharing.metier;

import java.util.ArrayList;
import java.util.List;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import fr.afcepf.ai89.esharing.data.IDAOAem;
import fr.afcepf.ai89.esharing.data.IDAOImgAem;
import fr.afcepf.ai89.esharing.data.IDAOIndisponibilite;
import fr.afcepf.ai89.esharing.data.IDAOInvisibiliteAem;
import fr.afcepf.ai89.esharing.data.IDAOPromotionAem;
import fr.afcepf.ai89.esharing.data.IDAOPromotionParc;
import fr.afcepf.ai89.esharing.data.IDAOValeur;
import fr.afcepf.ai89.esharing.entity.Aem;
import fr.afcepf.ai89.esharing.entity.ImgAem;
import fr.afcepf.ai89.esharing.entity.Indisponibilite;
import fr.afcepf.ai89.esharing.entity.InvisibiliteAem;
import fr.afcepf.ai89.esharing.entity.PromotionAem;
import fr.afcepf.ai89.esharing.entity.PromotionParc;
import fr.afcepf.ai89.esharing.entity.Proprietaire;
import fr.afcepf.ai89.esharing.entity.Valeur;

public class BusinessGestionParcAem implements IBusinessGestionParcAem {

	@Override
	public int addAem(Aem aem) {
		try {

			Context ctx;
			ctx = new InitialContext();
			IDAOAem proxyDataAem = null;

			try {

				proxyDataAem = (IDAOAem) ctx
						.lookup("java:global/ESharingPhase1/DAOAem!fr.afcepf.ai89.esharing.data.IDAOAem");

			} catch (Exception e) {

				proxyDataAem = (IDAOAem) ctx
						.lookup("ESharingPhase1/DAOAem!fr.afcepf.ai89.esharing.data.IDAOAem");

			}

			return proxyDataAem.addAem(aem);

		} catch (NamingException e) {

			e.printStackTrace();

		}
		return -1;
	}

	@Override
	public int majAem(Aem aem) {
		try {

			Context ctx;
			ctx = new InitialContext();
			IDAOAem proxyDataAem = null;

			try {

				proxyDataAem = (IDAOAem) ctx
						.lookup("java:global/ESharingPhase1/DAOAem!fr.afcepf.ai89.esharing.data.IDAOAem");

			} catch (Exception e) {

				proxyDataAem = (IDAOAem) ctx
						.lookup("ESharingPhase1/DAOAem!fr.afcepf.ai89.esharing.data.IDAOAem");

			}

			return proxyDataAem.majAem(aem);

		} catch (NamingException e) {

			e.printStackTrace();

		}
		return -1;
	}

	@Override
	public int retirerAem(Aem aem) {
		try {

			Context ctx;
			ctx = new InitialContext();
			IDAOAem proxyDataAem = null;

			try {

				proxyDataAem = (IDAOAem) ctx
						.lookup("java:global/ESharingPhase1/DAOAem!fr.afcepf.ai89.esharing.data.IDAOAem");

			} catch (Exception e) {

				proxyDataAem = (IDAOAem) ctx
						.lookup("ESharingPhase1/DAOAem!fr.afcepf.ai89.esharing.data.IDAOAem");

			}

			return proxyDataAem.retirerAem(aem);

		} catch (NamingException e) {

			e.printStackTrace();

		}
		return -1;
	}

	@Override
	public List<Aem> getMesAems(Proprietaire prop) {
		try {

			Context ctx;
			ctx = new InitialContext();
			IDAOAem proxyDataAem = null;

			try {

				proxyDataAem = (IDAOAem) ctx
						.lookup("java:global/ESharingPhase1/DAOAem!fr.afcepf.ai89.esharing.data.IDAOAem");

			} catch (Exception e) {

				proxyDataAem = (IDAOAem) ctx
						.lookup("ESharingPhase1/DAOAem!fr.afcepf.ai89.esharing.data.IDAOAem");

			}

			return proxyDataAem.getAems(prop);

		} catch (NamingException e) {

			e.printStackTrace();

		}
		return null;
	}

	@Override
	public int addIndispo(Indisponibilite indispo) {
		try {

			Context ctx;
			ctx = new InitialContext();
			IDAOIndisponibilite proxyDataIndispo = null;

			try {

				proxyDataIndispo = (IDAOIndisponibilite) ctx
						.lookup("java:global/ESharingPhase1/DAOIndisponibilite!fr.afcepf.ai89.esharing.data.IDAOIndisponibilite");

			} catch (Exception e) {

				proxyDataIndispo = (IDAOIndisponibilite) ctx
						.lookup("ESharingPhase1/DAOIndisponibilite!fr.afcepf.ai89.esharing.data.IDAOIndisponibilite");

			}

			return proxyDataIndispo.addIndispo(indispo);

		} catch (NamingException e) {

			e.printStackTrace();

		}
		return -1;
	}

	@Override
	public int majIndispo(Indisponibilite indispo) {
		try {

			Context ctx;
			ctx = new InitialContext();
			IDAOIndisponibilite proxyDataIndispo = null;

			try {

				proxyDataIndispo = (IDAOIndisponibilite) ctx
						.lookup("java:global/ESharingPhase1/DAOIndisponibilite!fr.afcepf.ai89.esharing.data.IDAOIndisponibilite");

			} catch (Exception e) {

				proxyDataIndispo = (IDAOIndisponibilite) ctx
						.lookup("ESharingPhase1/DAOIndisponibilite!fr.afcepf.ai89.esharing.data.IDAOIndisponibilite");

			}

			return proxyDataIndispo.majIndispo(indispo);

		} catch (NamingException e) {

			e.printStackTrace();

		}
		return -1;
	}

	@Override
	public int retirerIndispo(Indisponibilite indispo) {
		try {

			Context ctx;
			ctx = new InitialContext();
			IDAOIndisponibilite proxyDataIndispo = null;

			try {

				proxyDataIndispo = (IDAOIndisponibilite) ctx
						.lookup("java:global/ESharingPhase1/DAOIndisponibilite!fr.afcepf.ai89.esharing.data.IDAOIndisponibilite");

			} catch (Exception e) {

				proxyDataIndispo = (IDAOIndisponibilite) ctx
						.lookup("ESharingPhase1/DAOIndisponibilite!fr.afcepf.ai89.esharing.data.IDAOIndisponibilite");

			}

			return proxyDataIndispo.retirerIndispo(indispo);

		} catch (NamingException e) {

			e.printStackTrace();

		}
		return -1;
	}

	@Override
	public int addInvisAem(InvisibiliteAem invisAem) {
		try {

			Context ctx;
			ctx = new InitialContext();
			IDAOInvisibiliteAem proxyDataInvis = null;

			try {

				proxyDataInvis = (IDAOInvisibiliteAem) ctx
						.lookup("java:global/ESharingPhase1/DAOInvisibiliteAem!fr.afcepf.ai89.esharing.data.IDAOInvisibiliteAem");

			} catch (Exception e) {

				proxyDataInvis = (IDAOInvisibiliteAem) ctx
						.lookup("ESharingPhase1/DAOInvisibiliteAem!fr.afcepf.ai89.esharing.data.IDAOInvisibiliteAem");

			}

			return proxyDataInvis.addInvisAem(invisAem);

		} catch (NamingException e) {

			e.printStackTrace();

		}
		return -1;

	}

	@Override
	public int majInvisAem(InvisibiliteAem invisAem) {
		try {

			Context ctx;
			ctx = new InitialContext();
			IDAOInvisibiliteAem proxyDataInvis = null;

			try {

				proxyDataInvis = (IDAOInvisibiliteAem) ctx
						.lookup("java:global/ESharingPhase1/DAOInvisibiliteAem!fr.afcepf.ai89.esharing.data.IDAOInvisibiliteAem");

			} catch (Exception e) {

				proxyDataInvis = (IDAOInvisibiliteAem) ctx
						.lookup("ESharingPhase1/DAOInvisibiliteAem!fr.afcepf.ai89.esharing.data.IDAOInvisibiliteAem");

			}

			return proxyDataInvis.majInvisAem(invisAem);

		} catch (NamingException e) {

			e.printStackTrace();

		}
		return -1;
	}

	@Override
	public int retirerInvisAem(InvisibiliteAem invisAem) {
		try {

			Context ctx;
			ctx = new InitialContext();
			IDAOInvisibiliteAem proxyDataInvis = null;

			try {

				proxyDataInvis = (IDAOInvisibiliteAem) ctx
						.lookup("java:global/ESharingPhase1/DAOInvisibiliteAem!fr.afcepf.ai89.esharing.data.IDAOInvisibiliteAem");

			} catch (Exception e) {

				proxyDataInvis = (IDAOInvisibiliteAem) ctx
						.lookup("ESharingPhase1/DAOInvisibiliteAem!fr.afcepf.ai89.esharing.data.IDAOInvisibiliteAem");

			}

			return proxyDataInvis.retirerInvisAem(invisAem);

		} catch (NamingException e) {

			e.printStackTrace();

		}
		return -1;
	}

	@Override
	public int addImgAem(ImgAem imgAem) {
		try {

			Context ctx;
			ctx = new InitialContext();
			IDAOImgAem proxyDataImgAem = null;

			try {

				proxyDataImgAem = (IDAOImgAem) ctx
						.lookup("java:global/ESharingPhase1/DAOImgAem!fr.afcepf.ai89.esharing.data.IDAOImgAem");

			} catch (Exception e) {

				proxyDataImgAem = (IDAOImgAem) ctx
						.lookup("ESharingPhase1/DAOImgAem!fr.afcepf.ai89.esharing.data.IDAOImgAem");

			}

			return proxyDataImgAem.addImgAem(imgAem);

		} catch (NamingException e) {

			e.printStackTrace();

		}
		return -1;
	}

	@Override
	public int majImgAem(ImgAem imgAem) {
		try {

			Context ctx;
			ctx = new InitialContext();
			IDAOImgAem proxyDataImgAem = null;

			try {

				proxyDataImgAem = (IDAOImgAem) ctx
						.lookup("java:global/ESharingPhase1/DAOImgAem!fr.afcepf.ai89.esharing.data.IDAOImgAem");

			} catch (Exception e) {

				proxyDataImgAem = (IDAOImgAem) ctx
						.lookup("ESharingPhase1/DAOImgAem!fr.afcepf.ai89.esharing.data.IDAOImgAem");

			}

			return proxyDataImgAem.majImgAem(imgAem);

		} catch (NamingException e) {

			e.printStackTrace();

		}
		return -1;
	}

	@Override
	public int changerValeur(Valeur valeur) {
		try {

			Context ctx;
			ctx = new InitialContext();
			IDAOValeur proxyDataValeur = null;

			try {

				proxyDataValeur = (IDAOValeur) ctx
						.lookup("java:global/ESharingPhase1/DAOValeur!fr.afcepf.ai89.esharing.data.IDAOValeur");

			} catch (Exception e) {

				proxyDataValeur = (IDAOValeur) ctx
						.lookup("ESharingPhase1/DAOValeur!fr.afcepf.ai89.esharing.data.IDAOValeur");

			}

			return proxyDataValeur.valoriser(valeur);

		} catch (NamingException e) {

			e.printStackTrace();

		}
		return -1;
	}

	@Override
	public List<PromotionAem> getPromosAem(Aem aem) {
		try {

			Context ctx;
			ctx = new InitialContext();
			IDAOPromotionAem proxyDataPromoAem = null;

			try {

				proxyDataPromoAem = (IDAOPromotionAem) ctx
						.lookup("java:global/ESharingPhase1/DAOPromotionAem!fr.afcepf.ai89.esharing.data.IDAOPromotionAem");

			} catch (Exception e) {

				proxyDataPromoAem = (IDAOPromotionAem) ctx
						.lookup("ESharingPhase1/DAOPromotionAem!fr.afcepf.ai89.esharing.data.IDAOPromotionAem");

			}

			return proxyDataPromoAem.getPromosAem(aem);

		} catch (NamingException e) {

			e.printStackTrace();

		}
		return null;
	}

	@Override
	public int promouvoirAem(PromotionAem promoAem) {
		try {

			Context ctx;
			ctx = new InitialContext();
			IDAOPromotionAem proxyDataPromoAem = null;

			try {

				proxyDataPromoAem = (IDAOPromotionAem) ctx
						.lookup("java:global/ESharingPhase1/DAOPromotionAem!fr.afcepf.ai89.esharing.data.IDAOPromotionAem");

			} catch (Exception e) {

				proxyDataPromoAem = (IDAOPromotionAem) ctx
						.lookup("ESharingPhase1/DAOPromotionAem!fr.afcepf.ai89.esharing.data.IDAOPromotionAem");

			}

			return proxyDataPromoAem.promouvoirAem(promoAem);

		} catch (NamingException e) {

			e.printStackTrace();

		}
		return -1;

	}

	@Override
	public int majPromoAem(PromotionAem promoAem) {
		try {

			Context ctx;
			ctx = new InitialContext();
			IDAOPromotionAem proxyDataPromoAem = null;

			try {

				proxyDataPromoAem = (IDAOPromotionAem) ctx
						.lookup("java:global/ESharingPhase1/DAOPromotionAem!fr.afcepf.ai89.esharing.data.IDAOPromotionAem");

			} catch (Exception e) {

				proxyDataPromoAem = (IDAOPromotionAem) ctx
						.lookup("ESharingPhase1/DAOPromotionAem!fr.afcepf.ai89.esharing.data.IDAOPromotionAem");

			}

			return proxyDataPromoAem.majPromoAem(promoAem);

		} catch (NamingException e) {

			e.printStackTrace();

		}
		return -1;
	}

	@Override
	public List<PromotionParc> getPromosParc() {
		try {

			Context ctx;
			ctx = new InitialContext();
			IDAOPromotionParc proxyDataPromoParc = null;

			try {

				proxyDataPromoParc = (IDAOPromotionParc) ctx
						.lookup("java:global/ESharingPhase1/DAOPromoParc!fr.afcepf.ai89.esharing.data.IDAOPromotionParc");

			} catch (Exception e) {

				proxyDataPromoParc = (IDAOPromotionParc) ctx
						.lookup("ESharingPhase1/DAOPromoParc!fr.afcepf.ai89.esharing.data.IDAOPromotionParc");

			}

			return proxyDataPromoParc.getPromosParc();

		} catch (NamingException e) {

			e.printStackTrace();

		}
		return null;
	}

	@Override
	public int promouvoirParc(PromotionParc promoParc) {
		try {

			Context ctx;
			ctx = new InitialContext();
			IDAOPromotionParc proxyDataPromoParc = null;

			try {

				proxyDataPromoParc = (IDAOPromotionParc) ctx
						.lookup("java:global/ESharingPhase1/DAOPromoParc!fr.afcepf.ai89.esharing.data.IDAOPromotionParc");

			} catch (Exception e) {

				proxyDataPromoParc = (IDAOPromotionParc) ctx
						.lookup("ESharingPhase1/DAOPromoParc!fr.afcepf.ai89.esharing.data.IDAOPromotionParc");

			}

			return proxyDataPromoParc.promouvoirParc(promoParc);

		} catch (NamingException e) {

			e.printStackTrace();

		}
		return -1;
	}

	@Override
	public int majPromoParc(PromotionParc promoParc) {
		try {

			Context ctx;
			ctx = new InitialContext();
			IDAOPromotionParc proxyDataPromoParc = null;

			try {

				proxyDataPromoParc = (IDAOPromotionParc) ctx
						.lookup("java:global/ESharingPhase1/DAOPromoParc!fr.afcepf.ai89.esharing.data.IDAOPromotionParc");

			} catch (Exception e) {

				proxyDataPromoParc = (IDAOPromotionParc) ctx
						.lookup("ESharingPhase1/DAOPromoParc!fr.afcepf.ai89.esharing.data.IDAOPromotionParc");

			}

			return proxyDataPromoParc.majPromoParc(promoParc);

		} catch (NamingException e) {

			e.printStackTrace();

		}
		return -1;
	}

	@Override
	public List<Indisponibilite> getIndispos(Aem aem) {
		
		List<Indisponibilite> lesIndis = new ArrayList<Indisponibilite>();
		
		try {

			Context ctx;
			ctx = new InitialContext();
			IDAOIndisponibilite proxyDataIndis = null;

			try {

				proxyDataIndis = (IDAOIndisponibilite) ctx
						.lookup("java:global/ESharingPhase1/DAOIndisponibilite!fr.afcepf.ai89.esharing.data.IDAOIndisponibilite");

			} catch (Exception e) {

				proxyDataIndis = (IDAOIndisponibilite) ctx
						.lookup("ESharingPhase1/DAOIndisponibilite!fr.afcepf.ai89.esharing.data.IDAOIndisponibilite");

			}

			lesIndis = proxyDataIndis.getIndispos(aem);

		} catch (NamingException e) {

			e.printStackTrace();

		}
		return lesIndis;

	}

	@Override
	public List<InvisibiliteAem> getPeriodesInvis(Aem aem) {
		
		List<InvisibiliteAem> lesInvis = new ArrayList<InvisibiliteAem>();
		
		try {

			Context ctx;
			ctx = new InitialContext();
			IDAOInvisibiliteAem proxyDataInvis = null;

			try {

				proxyDataInvis = (IDAOInvisibiliteAem) ctx
						.lookup("java:global/ESharingPhase1/DAOInvisibiliteAem!fr.afcepf.ai89.esharing.data.IDAOInvisibiliteAem");

			} catch (Exception e) {

				proxyDataInvis = (IDAOInvisibiliteAem) ctx
						.lookup("ESharingPhase1/DAOInvisibiliteAem!fr.afcepf.ai89.esharing.data.IDAOInvisibiliteAem");

			}

			lesInvis = proxyDataInvis.getInvisAem(aem);

		} catch (NamingException e) {

			e.printStackTrace();

		}
		return lesInvis;

	}

}
